// POJ1836 -- Alignment
// 陈锋
#include <algorithm>
#include <cstdio>
#include <cstring>
const int NN = 1000 + 4;
using namespace std;
int F[NN], G[NN];
float A[NN];
int main() {
  for (int n, ans = 0; scanf("%d", &n) == 1;) {
    fill_n(F, n, 0), fill_n(G, n, 0);
    for (int i = 1; i <= n; i++) scanf("%f", &A[i]);
    for (int i = 1; i <= n; i++) {
      F[i] = 1;  // F[i]: 以i为结尾的最长LIS长度
      for (int j = i - 1; j >= 1; j--)
        if (A[i] > A[j] && F[i] < F[j] + 1) F[i] = F[j] + 1;
    }

    for (int i = n; i >= 1; i--) {
      G[i] = 1;  // G[i]: 以i为开始的最长LDS
      for (int j = i + 1; j <= n; j++)
        if (A[i] > A[j] && G[i] < G[j] + 1) G[i] = G[j] + 1;
    }

    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) ans = max(ans, F[i] + G[j]);
    printf("%d\n", n - ans);
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》 9.4.1一节中 最长上升子序列问题
*/
// Accepted 47ms 356kB 827 G++2020-12-2621:15:35 22233203